package com.colin.app.fragment.recyclerview;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;

import com.colin.app.R;
import com.colin.app.app.AppActivity;
import com.colin.app.app.BaseModelImpl;
import com.colin.app.bean.ItemBean;
import com.colin.library.other.Constants;
import com.colin.library.other.Url;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Colin on 2017/1/15.
 */

public class RecyclerViewModelImpl extends BaseModelImpl implements RecyclerViewContract.RecyclerViewModel {
    private int fragment_id;

    public RecyclerViewModelImpl(int fragment_id) {
        this.fragment_id = fragment_id;
    }

    @Override
    public RecyclerView.LayoutManager getLayoutManager(AppActivity mAppActivity) {
        RecyclerView.LayoutManager layoutManager = null;
        if (fragment_id == Constants.FRAGMENT_RECYCLER_VIEW_TYPE_LIST) {
            layoutManager = new LinearLayoutManager(mAppActivity, LinearLayoutManager.VERTICAL, false);
        } else if (fragment_id == Constants.FRAGMENT_RECYCLER_VIEW_TYPE_GRID) {
            final int grid_columns = mAppActivity.getResources().getInteger(R.integer.grid_columns);
            layoutManager = new GridLayoutManager(mAppActivity, grid_columns);
        } else if (fragment_id == Constants.FRAGMENT_RECYCLER_VIEW_TYPE_STAGGERED) {
            final int grid_columns = mAppActivity.getResources().getInteger(R.integer.grid_columns);
            layoutManager = new StaggeredGridLayoutManager(grid_columns, OrientationHelper.VERTICAL);
        }
        return layoutManager;
    }

    @Override
    public List<ItemBean> getItemBeanList(int page) {
        List<ItemBean> itemBeanList = new ArrayList<>();
        String title = "";
        if (fragment_id == Constants.FRAGMENT_RECYCLER_VIEW_TYPE_LIST) {
            title = "列表";
        } else if (fragment_id == Constants.FRAGMENT_RECYCLER_VIEW_TYPE_GRID) {
            title = "网格";
        } else if (fragment_id == Constants.FRAGMENT_RECYCLER_VIEW_TYPE_STAGGERED) {
            title = "瀑布流";
        }
        ItemBean itemBean = null;
        for (int i = 0; i < pageSize; i++) {
            itemBean = new ItemBean().setImage(Url.image_url[i])
                    .setImageLarge(Url.image_url[i])
                    .setAuthor_intro(title)
                    .setTitle(title + "-->\t" + String.valueOf((page - 1) * pageSize + i + 1))
                    .setCatalog(title);
            itemBeanList.add(itemBean);
        }
        return itemBeanList;
    }
}
